home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Sample Code / Snippets / Toolbox / Vertest / Vertest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-09  |  10.4 KB  |  412 lines  |  [TEXT/MPS ]

  1. /*______________________________________________________*/
  2. /*                            C Shell                        */
  3. /*                          by                          */
  4. /*                  RICHARD P. COLLYER                  */
  5. /*                       09/02/87                       */
  6. /*______________________________________________________*/
  7.  
  8. #include    <CType.h>
  9. #include    <Quickdraw.h>
  10. #include    <Windows.h>
  11. #include    <OSUtils.h>
  12. #include    <Controls.h>
  13. #include    <desk.h>
  14. #include    <dialogs.h>
  15. #include    <Events.h>
  16. #include    <Files.h>
  17. #include    <Memory.h>
  18. #include    <Menus.h>
  19. #include    <Notification.h>
  20. #include    <OSEvents.h>
  21. #include    <Packages.h>
  22. #include    <Palettes.h>
  23. #include    <Resources.h>
  24. #include    <SANE.h>
  25. #include    <SegLoad.h>
  26. #include    <Sound.h>
  27. #include    <String.h>
  28. #include    <ToolUtils.h>
  29. #include    <StdIO.h>
  30. #include    <math.h>
  31. #include    <TextUtils.h>
  32.  
  33. extern _DataInit();
  34.  
  35. #define    TRUE            0xFF
  36. #define    FALSE            0
  37. #define    VERSION            1
  38. #define    SR_BIT            0
  39.  
  40. #define    appleID            128            
  41. #define    appleMenu        0
  42. #define    aboutMeCommand    1
  43.  
  44. #define    fileID            129
  45. #define    startCommand    1
  46. #define    quitCommand     2
  47.  
  48. #define    editID            130
  49.  
  50. #define    aboutMeDLOG        128
  51. #define    okButton        1
  52. #define    authorItem        2
  53. #define    languageItem    3
  54.  
  55. #define    nocolorID        130
  56. #define    no68020            133
  57. #define    no68881            132
  58. #define    no256            134
  59. #define    nosys6            135
  60.  
  61. long                Tick;
  62. int                    yieldTime, err, numcolor, offLeft, offTop, offRight, offBottom;
  63. Rect                screenRect, BaseRect, TotalRect, minRect;
  64. WindowPtr            whichWindow, myWindow;
  65. CTabHandle            mycolors;
  66. PaletteHandle        srcPalette;
  67. MenuHandle            mymenu1, mymenu2, mymenu0;
  68. EventRecord         myEvent;
  69. Boolean                DoneFlag;
  70. GDHandle            theGDevice;
  71. SysEnvRec            theWorld;
  72. OSErr                OSys;
  73.  
  74. #ifdef powerc
  75.    QDGlobals    qd;
  76. #endif
  77.  
  78. /*______________________________________________________*/
  79. /*                What ever You want                    */
  80. /*______________________________________________________*/
  81. void start()
  82. {
  83.  
  84.     VersRecHndl version;
  85.     StringPtr messagePtr;
  86.     Str255 longMessage, countsstrPtr;
  87.     //char *countsstrPtr, countstr;
  88.     
  89.     //countsstrPtr = &countstr;
  90.  
  91.     version = (VersRecHndl) GetResource ('vers', 1);
  92.     
  93.     messagePtr = (StringPtr) (((unsigned long) &(**version).shortVersion[1]) + 
  94.             ((**version).shortVersion[0]));
  95.  
  96.     BlockMove((Ptr) messagePtr, &longMessage, ((unsigned char) *messagePtr) + 1);
  97.  
  98. //short version
  99.     MoveTo(10,10);
  100.     DrawString((**version).shortVersion);
  101. //long version
  102.     MoveTo(10,30);
  103.     DrawString(longMessage);
  104. //country code
  105.     MoveTo(10,50);
  106.     NumToString((**version).countryCode,countsstrPtr);
  107.     DrawString(countsstrPtr);
  108. //major rev
  109.     MoveTo(10,70);
  110.     NumToString((**version).numericVersion.majorRev,countsstrPtr);
  111.     DrawString(countsstrPtr);
  112. // minorAndBugRev
  113.     MoveTo(10,90);
  114.     NumToString((**version).numericVersion.minorAndBugRev,countsstrPtr);
  115.     DrawString(countsstrPtr);
  116. //stage
  117.     MoveTo(10,110);
  118.     NumToString((**version).numericVersion.stage,countsstrPtr);
  119.     DrawString(countsstrPtr);
  120. // non rel rev
  121.     MoveTo(10,130);
  122.     NumToString((**version).numericVersion.nonRelRev,countsstrPtr);
  123.     DrawString(countsstrPtr);
  124.     
  125.     return;
  126. }
  127.  
  128. /*______________________________________________________*/
  129. /*                 About Prog Dialog                    */
  130. /*______________________________________________________*/
  131. void showAboutMeDialog()
  132. {
  133.     GrafPtr     savePort;
  134.     DialogPtr    theDialog;
  135.     short        itemHit;
  136.  
  137.     GetPort(&savePort);
  138.     theDialog = GetNewDialog(aboutMeDLOG, nil, (WindowPtr) -1);
  139.     SetPort(theDialog);
  140.  
  141.     do {
  142.         ModalDialog(nil, &itemHit);
  143.     } while (itemHit != okButton);
  144.  
  145.     CloseDialog(theDialog);
  146.  
  147.     SetPort(savePort);
  148.     return;
  149. }
  150.  
  151. /*______________________________________________________*/
  152. /*                 Do Menu Function                     */
  153. /*______________________________________________________*/
  154. void doCommand(mResult)
  155.     long    mResult;
  156. {
  157.     int                     theMenu, theItem;
  158.     char                    daName[256];
  159.     GrafPtr                 savePort;
  160.  
  161.     theItem = LoWord(mResult);
  162.     theMenu = HiWord(mResult);
  163.     
  164.     switch (theMenu) {
  165. /*______________________________________________________*/
  166. /*                    Do Apple Menu                     */
  167. /*______________________________________________________*/
  168.         case appleID:
  169.             if (theItem == aboutMeCommand)
  170.                 showAboutMeDialog();
  171.             else {
  172.                 GetItem(mymenu0, theItem, daName);
  173.                 GetPort(&savePort);
  174.                 (void) OpenDeskAcc(daName);
  175.                 SetPort(savePort);
  176.             }
  177.             break;
  178. /*______________________________________________________*/
  179. /*                     Do File Menu                     */
  180. /*______________________________________________________*/
  181.         case fileID:
  182.             switch (theItem) {
  183.                 case startCommand:
  184.                     start();
  185.                     break;
  186.                 case quitCommand:
  187.                     DoneFlag = TRUE;
  188.                     break;
  189.                 default:
  190.                     break;
  191.                 }
  192.             break;
  193. /*______________________________________________________*/
  194. /*                     Do Edit Menu                     */
  195. /*______________________________________________________*/
  196.         case editID:
  197.             switch (theItem) {
  198.                 default:
  199.                     break;
  200.                 }
  201.             break;
  202.         default:
  203.             break;
  204.         }
  205.     HiliteMenu(0);
  206.     return;
  207. }
  208.  
  209.  
  210. /*______________________________________________________*/
  211. /*               Initialization traps                   */
  212. /*______________________________________________________*/
  213. void init()
  214. {
  215.     RgnHandle        tempRgn;
  216.     
  217.     UnloadSeg(_DataInit);
  218.     InitGraf(&qd.thePort);
  219.     FlushEvents(everyEvent, 0);
  220.     InitWindows();
  221.     InitDialogs(nil);
  222.     InitCursor();
  223. /*______________________________________________________*/
  224. /*            If not right Machine then stop            */
  225. /*______________________________________________________*/
  226.     OSys = SysEnvirons(VERSION,&theWorld);
  227.     /*if(!theWorld.hasColorQD) {
  228.         crashDia = GetNewDialog (nocolorID, nil, (WindowPtr) -1);
  229.         DrawDialog (crashDia);
  230.         Delay (300, tick);
  231.         ExitToShell();
  232.         }
  233.     if(theWorld.processor != env68020) {
  234.         crashDia = GetNewDialog (no68020, nil, (WindowPtr) -1);
  235.         DrawDialog (crashDia);
  236.         Delay (300, tick);
  237.         ExitToShell();
  238.         }
  239.     if(!theWorld.hasFPU) {
  240.         crashDia = GetNewDialog (no68881, nil, (WindowPtr) -1);
  241.         DrawDialog (crashDia);
  242.         Delay (300, tick);
  243.         ExitToShell();
  244.         }
  245.     if(theWorld.systemVersion < 0x0600) {
  246.         crashDia = GetNewDialog (nosys6, nil, (WindowPtr) -1);
  247.         DrawDialog (crashDia);
  248.         Delay (300, tick);
  249.         ExitToShell();
  250.         }*/
  251.             
  252. /*______________________________________________________*/
  253. /*                     Set Rects                        */
  254. /*______________________________________________________*/
  255.     screenRect = qd.screenBits.bounds;
  256.     offLeft = 0;
  257.     offTop = 0;
  258.     offRight = screenRect.right;
  259.     offBottom = screenRect.bottom;
  260.     SetRect(&BaseRect, 40, 60, 472, 282);
  261.     tempRgn = GetGrayRgn();
  262.     HLock ((Handle) tempRgn);
  263.     TotalRect = (**tempRgn).rgnBBox;
  264.     SetRect(&minRect, 80, 80, (**tempRgn).rgnBBox.right - 40, 
  265.                 (**tempRgn).rgnBBox.bottom - 40);
  266.     HUnlock ((Handle) tempRgn);
  267.  
  268. /*______________________________________________________*/
  269. /*        Open Window & set Palette & Picture           */
  270. /*______________________________________________________*/
  271.     theGDevice = GetMainDevice();
  272.     HLock ((Handle) theGDevice);
  273.     mycolors = (**(**theGDevice).gdPMap).pmTable;
  274.     numcolor = (**(**theGDevice).gdPMap).pixelSize;
  275.     HUnlock((Handle) theGDevice);
  276.     switch (numcolor) {
  277.         case 1:
  278.             numcolor = 2;
  279.             break;
  280.         case 2:
  281.             numcolor = 4;
  282.             break;
  283.         case 4:
  284.             numcolor = 16;
  285.             break;
  286.         case 8:
  287.             numcolor = 256;
  288.             break;
  289.         }
  290.     
  291.     myWindow = NewCWindow(nil, &BaseRect, "", TRUE, zoomDocProc, 
  292.                             (WindowPtr) -1, TRUE, 150);
  293.     SetPort((WindowPtr) myWindow);
  294.     DrawGrowIcon (myWindow);
  295.  
  296.     srcPalette = NewPalette (numcolor, mycolors, pmCourteous, 0);
  297.     SetPalette ((WindowPtr) myWindow, srcPalette, TRUE);
  298.     
  299. /*______________________________________________________*/
  300. /*                    Set menus                         */
  301. /*______________________________________________________*/
  302.     mymenu0 = GetMenu(appleID);
  303.     AddResMenu(mymenu0, 'DRVR');
  304.     InsertMenu(mymenu0,0);
  305.     mymenu1 = newmenu(129,"File");
  306.     appendmenu(mymenu1,"Start;Quit");
  307.     InsertMenu(mymenu1,0);
  308.     mymenu2 = newmenu(130,"Edit");
  309.     InsertMenu(mymenu2,0);
  310.     DrawMenuBar();
  311.  
  312. /*______________________________________________________*/
  313. /*                  Init variables                      */
  314. /*______________________________________________________*/
  315.     DoneFlag = FALSE;
  316.     yieldTime = 0;
  317.     return;
  318. }
  319.  
  320. main()
  321. {
  322.     Boolean        track;
  323.     long        growResult;
  324. /*______________________________________________________*/
  325. /*                   Main Event loop                    */
  326. /*______________________________________________________*/
  327.     init();
  328.     for ( ;; ) {
  329.         if (DoneFlag) {
  330.             ExitToShell();
  331.             }
  332.         if (WaitNextEvent(everyEvent, &myEvent, yieldTime, nil)) {
  333.             switch (myEvent.what) {
  334.                 case mouseDown:
  335.                     switch (FindWindow(myEvent.where, &whichWindow)) {
  336.                         case inSysWindow:
  337.                             SystemClick(&myEvent, whichWindow);
  338.                             break;
  339.                         case inMenuBar:
  340.                             doCommand(MenuSelect(myEvent.where));
  341.                             break;
  342.                         case inContent:
  343.                             break;
  344.                         case inDrag:
  345.                             DragWindow (whichWindow, myEvent.where, &TotalRect);
  346.                             EraseRect (&whichWindow->portRect);
  347.                             DrawGrowIcon (whichWindow);
  348.                             break;
  349.                         case inGrow:
  350.                             growResult = GrowWindow (whichWindow, myEvent.where,
  351.                                                     &minRect);
  352.                             SizeWindow(whichWindow, LoWord(growResult), 
  353.                                     HiWord(growResult), TRUE);
  354.                             EraseRect (&whichWindow->portRect);
  355.                             DrawGrowIcon (whichWindow);
  356.                             break;
  357.                         case inGoAway:
  358.                             track = TrackGoAway (whichWindow, myEvent.where);
  359.                             if (track)
  360.                                 CloseWindow (whichWindow);
  361.                             break;
  362.                         case inZoomIn:
  363.                             track = TrackBox (whichWindow, myEvent.where, inZoomIn);
  364.                             if (track) {
  365.                                 ZoomWindow (whichWindow, inZoomIn, TRUE);
  366.                                 EraseRect (&whichWindow->portRect);
  367.                                 DrawGrowIcon (whichWindow);
  368.                                 }
  369.                             break;
  370.                         case inZoomOut:
  371.                             track = TrackBox (whichWindow, myEvent.where, inZoomOut);
  372.                             if (track) {
  373.                                 ZoomWindow (whichWindow, inZoomOut, TRUE);
  374.                                 EraseRect (&whichWindow->portRect);
  375.                                 DrawGrowIcon (whichWindow);
  376.                                 }
  377.                             break;
  378.                         default:
  379.                             break;
  380.                         }
  381.                     break;
  382.                 case keyDown:
  383.                     break;
  384.                 case autoKey:
  385.                     break;
  386.                 case updateEvt:
  387.                     if ((WindowPtr) myEvent.message == myWindow) {
  388.                         BeginUpdate((WindowPtr) myWindow);
  389.                         EndUpdate((WindowPtr) myWindow);
  390.                         }
  391.                     break;
  392.                 case diskEvt:
  393.                     break;
  394.                 case activateEvt:
  395.                     break;
  396.                 case app4Evt:
  397.                     if ((myEvent.message << 31) == 0) { /* Suspend */
  398.                         yieldTime = 30;
  399.                         HideWindow((WindowPtr) myWindow);
  400.                         }
  401.                     else { /* Resume */
  402.                         yieldTime = 0;
  403.                         ShowWindow((WindowPtr) myWindow);
  404.                         SetPort((WindowPtr) myWindow);
  405.                         }
  406.                     break;
  407.                 default:
  408.                     break;
  409.                 }
  410.             }
  411.         }
  412. }